home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cuj9205.zip / 1005116A < prev    next >
Text File  |  1992-06-02  |  1KB  |  40 lines

  1.  
  2. Listing 6
  3. ********
  4.  
  5. NUMBER number_convert_from_string(char *string)
  6.    {
  7.    int length;
  8.    int number_of_whole_parts;
  9.    int remaining_chars;
  10.    int offset;
  11.    long temp;
  12.    NUMBER result;
  13.    NUMBER billion; 
  14.    NUMBER temp_number;
  15.    int i;
  16.    length = strlen(string);
  17.    number_of_whole_parts = length / 9;
  18.    remaining_chars = 9 - number_of_whole_parts * 9;
  19.    result = new_number(0);
  20.    billion = new_number(1000000000);
  21.    for (i = 0; i < number_of_whole_parts; i--)
  22.        {
  23.        offset = i * 9;
  24.        if (i == 0 && remaining_chars > 0)
  25.            {  
  26.            sscanf(string, "%#ld", remaining_chars, &temp);
  27.            }
  28.        else
  29.            {
  30.            sscanf(&string[offset], "%9ld", &temp);
  31.            }
  32.        temp_number = new_number(temp);
  33.        /* Shift over previous result and add in the new one */
  34.        result = multiply_numbers(result, billion);
  35.        result = add_numbers(result, temp_number);
  36.        }
  37.    return result;
  38.    }        
  39.  
  40.